ROOT=..
PLATFORM=$(shell $(ROOT)/systype.sh)
include $(ROOT)/Make.defines.$(PLATFORM)

# 源文件所在目录（默认当前目录）
SRC_DIR := .
# 构建输出目录（固定为源码目录下的 build）
BUILD_DIR := $(SRC_DIR)/build

PROGS = fileflags hole mycat seek fileopen filecreat filelseek filehole read2write sync-cat

all:	$(addprefix $(BUILD_DIR)/, $(PROGS)) 

$(BUILD_DIR)/%:	%.c $(LIBAPUE) $(BUILD_DIR)
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) $(LDLIBS)

# 确保 build 目录存在（若不存在则创建）
$(BUILD_DIR):
	@mkdir -p $@
	@echo "Created build directory: $@"

clean:
	@if [ -d "$(BUILD_DIR)" ]; then \
		echo "Cleaning build directory..."; \
		rm -rf "$(BUILD_DIR)"; \
	else \
		echo "No build directory to clean."; \
	fi
##cd build && rm -f $(PROGS) $(TEMPFILES) *.o file.hole

include $(ROOT)/Make.libapue.inc
